package edu.ccut.saturn.studio.logic.parts;

import org.eclipse.draw2d.ChopboxAnchor;
import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.gef.EditPart;

import edu.ccut.saturn.studio.logic.figure.PageFigure;

public class BorderAnchor extends ChopboxAnchor {
	protected double angle;
	private IFigure figure;
	EditPart editPart;

	public BorderAnchor(IFigure figure) {
		super(figure);

		this.figure = figure;
	}

	public BorderAnchor(ShapeEditPart editPart) {

		this.editPart = editPart;
	}

	/**
	 * 重新计算Box.
	 */
	@Override
	protected Rectangle getBox() {
		Rectangle r = Rectangle.SINGLETON;
		// r.setBounds(new Rectangle(getOwner().getBounds().x
		// + getOwner().getBounds().width / 2 - 26,
		// getOwner().getBounds().y, 50, 50));
		if (figure instanceof PageFigure) {
			r.setBounds(new Rectangle(((PageFigure) figure).getImageFigure()
					.getBounds().x, ((PageFigure) figure).getImageFigure()
					.getBounds().y, ((PageFigure) figure).getImageFigure()
					.getBounds().width, ((PageFigure) figure).getImageFigure()
					.getBounds().height));
		} else {
			r.setBounds(new Rectangle(getOwner().getBounds().x
					+ getOwner().getBounds().width / 2 - 26, getOwner()
					.getBounds().y, 50, 50));
		}
		return r;
	}
}
